package com.mdxx.xczd.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.util.AttributeSet;
import android.view.View;
import com.mdxx.xczd.R;
import com.mdxx.xczd.bean.PatrolPointBean;
import java.util.List;

/**
 *保护点列表控件
 */
public class LocationView extends View {

	private Paint mPaint;
	private float xPos = 10;
	private List<PatrolPointBean> list;
	int singleHeight = 25;
	
	public LocationView(Context context) {
		this(context, null);
	}
	
	public LocationView(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}
	
	public LocationView(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		init();
	}

	private void init(){
		mPaint = new Paint();
		mPaint.setStyle(Style.FILL);
		mPaint.setTextSize(12);
		mPaint.setStrokeWidth(2);
	}
	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		int widthSize = MeasureSpec.getSize(widthMeasureSpec);
		int heightSize = singleHeight*list.size();
		setMeasuredDimension(widthSize, heightSize);
	}
  @Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);		
		for (int i = 0; i < list.size(); i++) {
			if(list.get(i).state == 1){
				mPaint.setColor(getResources().getColor(R.color.grgray));
			}else{
				mPaint.setColor(getResources().getColor(R.color.statebar_color));
			}
			float yPos = singleHeight * i + singleHeight;
			float baseline = yPos - singleHeight/2 + mPaint.getTextSize()/2 - mPaint.getFontMetrics().descent;
			canvas.drawCircle(xPos, yPos-singleHeight/2, 4, mPaint);
			canvas.drawText(list.get(i).siteName, xPos+15, baseline, mPaint);
			if(i>0){
				canvas.drawLine(xPos, yPos-singleHeight/2 -5, xPos, yPos-3*singleHeight/2 + 5, mPaint);
			}
		}		
	}
	
	public void setData(List<PatrolPointBean> list){		
		this.list = list;		
		invalidate();
	}	
}
